﻿<c:BaseControl x:Class="personalplaner.gui.stamm.views.HolidayStamm"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:bs="clr-namespace:personalplaner.business.stamm;assembly=personalplaner.business"
             xmlns:vm="clr-namespace:personalplaner.common.mvvm.factory;assembly=personalplaner.common"
             xmlns:fac="clr-namespace:personalplaner.gui.stamm.viewmodels.factories"
             vm:ViewModelLoader.FactoryType="{x:Type fac:HolidayStammModelFactory}"
             xmlns:c="clr-namespace:personalplaner.common.controls;assembly=personalplaner.common"
             xmlns:conv="clr-namespace:personalplaner.common.converters;assembly=personalplaner.common"
             Name="baseControl"
             Background="Transparent"
             Foreground="#E1000000">

    <Control.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/personalplaner.common;component/resources/styles/WhiteStyleTemplates.xaml"/>
                <ResourceDictionary>
                    <DataTemplate DataType="{x:Type bs:Person}">
                        <Grid Margin="0,0,20,0">
                            <Grid.ColumnDefinitions>
                                <!--<ColumnDefinition Width="30"/>-->
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>

                            <Grid.OpacityMask>
                                <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                                    <GradientStop Offset="0.0" Color="Black" />
                                    <GradientStop Offset="0.8" Color="Black" />
                                    <GradientStop Offset="1.0" Color="Transparent" />
                                </LinearGradientBrush>
                            </Grid.OpacityMask>

                            <!-- Create a trasparent border that keeps the width static -->
                            <Border Background="Transparent" Width="220" Grid.ColumnSpan="2"/>

                            <!--<TextBlock Text="{Binding PrsID}"/>-->
                            <TextBlock Name="txtName" Text="{Binding Name}" Grid.Column="0" Margin="5,0,5,0"/>
                            <TextBlock Name="txtNachName" Text="{Binding Nachname}" Grid.Column="1"/>
                        </Grid>

                        <DataTemplate.Triggers>
                            <DataTrigger Binding="{Binding PersonTyp}" Value="Zusatzperson">
                                <Setter TargetName="txtName" Property="Foreground" Value="Green"/>
                                <Setter TargetName="txtNachName" Property="Foreground" Value="Green"/>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding PersonTyp}" Value="Inaktiv">
                                <Setter TargetName="txtName" Property="Foreground" Value="Red"/>
                                <Setter TargetName="txtNachName" Property="Foreground" Value="Red"/>
                            </DataTrigger>
                        </DataTemplate.Triggers>

                    </DataTemplate>
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Control.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="220"/>
            <ColumnDefinition />
        </Grid.ColumnDefinitions>

        <Border BorderBrush="Transparent" BorderThickness="0" Background="Transparent" Margin="5,5,0,0" Padding="5" >
            <Grid>

                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition />
                </Grid.RowDefinitions>
                
                <CheckBox Margin="5,4,0,10" IsChecked="{Binding ShowAllPersonen}">
                    <TextBlock Text="Alle Personen" />
                </CheckBox>

                <ListBox ItemsSource="{Binding Personen}" SelectedItem="{Binding SelectedPerson}" Margin="5,10,0,0" Grid.Row="1" ScrollViewer.HorizontalScrollBarVisibility="Disabled"/>

            </Grid>
        </Border>

        <GridSplitter Width="4" Background="Transparent"/>
        
        <GroupBox Margin="0,5,5,0" Grid.Column="1">
            <Grid Margin="50,0,0,0">
                <Grid.Resources>
                    <conv:DateTimeToIsoConverter x:Key="dateToIso"/>
                </Grid.Resources>

                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="100"/>
                    <ColumnDefinition Width="150"/>
                    <!--<ColumnDefinition Width="100"/>-->
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>

                <TextBlock Text="Jahr"/>
                <ComboBox ItemsSource="{Binding Years}" SelectedItem="{Binding SelectedYear}" Grid.Column="1">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Jahr}" x:Name="txt" Foreground="Black" />

                            <DataTemplate.Triggers>
                                <DataTrigger Binding="{Binding Status}" Value="Inactive">
                                    <Setter TargetName="txt" Property="Foreground" Value="Gray"/>
                                </DataTrigger>
                            </DataTemplate.Triggers>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
                
                <TextBlock Text="Von" Grid.Row="1"/>
                <DatePicker DataContext="{Binding SelectedHoliday}" SelectedDate="{FocusBinding Von}" Grid.Row="1" Grid.Column="1"
                            IsEnabled="{Binding DataContext.IsWriteable, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}}"/>

                <TextBlock Text="Bis" Grid.Row="2"/>
                <DatePicker SelectedDate="{Binding SelectedHoliday.Bis}" Grid.Row="2" Grid.Column="1" IsEnabled="{Binding IsWriteable}"/>
                
                <Border BorderBrush="Black" BorderThickness="0,0,0,1" Background="Transparent" Grid.Row="3" Grid.ColumnSpan="3" Margin="10,50,50,0">
                    <Grid >
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="100"/>
                            <ColumnDefinition Width="100"/>
                            <!--<ColumnDefinition Width="*"/>-->
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="Von" FontWeight="Heavy"/>
                        <TextBlock Text="Bis" FontWeight="Heavy" Grid.Column="1"/>
                    </Grid>
                </Border>
                <ListBox ItemsSource="{Binding Holidays}" SelectedItem="{Binding SelectedHoliday}" Grid.Row="4" Grid.ColumnSpan="3" Margin="10,5,50,0">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="100"/>
                                    <ColumnDefinition Width="100"/>
                                    <!--<ColumnDefinition Width="*"/>-->
                                </Grid.ColumnDefinitions>
                                <TextBlock Text="{Binding Von, Converter={StaticResource dateToIso}}" VerticalAlignment="Top" />
                                <TextBlock Text="{Binding Bis, Converter={StaticResource dateToIso}}" Grid.Column="1" VerticalAlignment="Top"/>
                            </Grid>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>

            </Grid>
        </GroupBox>

        <StackPanel Grid.Row="1" Grid.ColumnSpan="4" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,20,40,20">
            <Button MinWidth="60" Margin="5" Command="{Binding DeleteCommand}">
                <TextBlock Text="Löschen"/>
            </Button>
            <Button MinWidth="60" Margin="5" Command="{Binding NewCommand}">
                <TextBlock Text="Neu"/>
            </Button>
            <Button MinWidth="60" Margin="5" Command="{Binding SaveCommand}">
                <TextBlock Text="Speichern"/>
            </Button>
            <Button MinWidth="60" Margin="5" IsDefault="True" Command="{Binding OkCommand}">
                <TextBlock Text="OK"/>
            </Button>
            <Button MinWidth="60" Margin="5" IsCancel="True" Command="{Binding CancelCommand}">
                <TextBlock Text="Abbrechen"/>
            </Button>
        </StackPanel>
    </Grid>
    
</c:BaseControl>
